Skip to content

Support ~~~ fences in the fenced-code-blocks extra - #776

Open
jayhemnani9910 wants to merge 1 commit into
trentm:masterfrom
jayhemnani9910:fix/tilde-fenced-code-blocks
Open

jayhemnani9910 wants to merge 1 commit into
trentm:masterfrom
jayhemnani9910:fix/tilde-fenced-code-blocks

Conversation

@jayhemnani9910

Copy link
Copy Markdown

The fenced-code-blocks extra only matches backtick fences, so a block fenced with ~~~ (CommonMark and GFM allow both, and Pandoc writes tildes) is not treated as code:

s = "Run:\n\n~~~\nls ~/x\n~~~\n"
markdown2.markdown(s, extras=["fenced-code-blocks"])
# '<p>Run:</p>\n\n<p>~~~\nls ~/x\n~~~</p>\n'
markdown2.markdown(s, extras=["fenced-code-blocks", "strike"])
# '<p>Run:</p>\n\n<p><s>~\nls ~/x\n~</s></p>\n'

The code ends up in a paragraph, and with strike the whole block is struck through.

The opening fence now accepts three or more ~ as well as backticks, the closing fence matches the same opener, and test() also checks for ~~~. Backticks inside a tilde block stay as code.

Added test/tm-cases/fenced_code_blocks_tilde, which fails before the change. The rest of python test.py gives the same results before and after (the existing knownfailure cases).

Only backtick fences were matched, so a ~~~ block rendered as a
paragraph, and with the strike extra it came out struck through.
@jayhemnani9910
jayhemnani9910 force-pushed the fix/tilde-fenced-code-blocks branch from 3a031c5 to c2ffb3c Compare November 12, 2026 08:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant